package communication;

import java.net.SocketException;

import com.illposed.osc.OSCListener;
import com.illposed.osc.OSCPortIn;

public class OSCExternalInput {

	OSCPortIn receiver;
	String[] protocol = {
			"/wiimote",
			"/nunchuk",
			"/nunchukJoystick",
			"/buttonAPressed",
			"/buttonAReleased",
			"/buttonBPressed",
			"/buttonBReleased",
			"/buttonMinusPressed",
			"/buttonMinusReleased",
			"/buttonPlusReleased",
			"/buttonPlusPressed",
			"/button1Pressed",
			"/button1Released",
			"/button2Pressed",
			"/button2Released",
			"/buttonHomePressed",
			"/buttonHomeReleased",
			"/buttonUpPressed",
			"/buttonUpReleased",
			"/buttonDownPressed",
			"/buttonDownReleased",
			"/buttonLeftPressed",
			"/buttonLeftReleased",
			"/buttonRightPressed",
			"/buttonRightReleased",
			"/buttonCPressed",
			"/buttonCReleased",
			"/buttonZPressed",
			"/buttonZReleased",
			"rescalla"
	};

	public OSCExternalInput(){
		try {
			receiver = new OSCPortIn(9999);
		} catch (SocketException e) {
			e.printStackTrace();
		}
	}

	public void startListening(OSCListener listener){
		System.out.println("Starting receiving messages...");
		for (int i = 0; i < protocol.length; i++) {
			receiver.addListener(protocol[i], listener);
		}
		receiver.startListening();
	}

}
